#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time    : 2025/4/25 16:34
@Author  : HZP
@File    : 1.RunnableParallel使用技巧.py
"""
from dotenv import load_dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableParallel
from langchain_openai import ChatOpenAI

load_dotenv()
prompt_one = ChatPromptTemplate.from_template("请帮讲一个{function}的科学原理")
prompt_two = ChatPromptTemplate.from_template("你是一名律师，请讲一个{topic}的冷笑话？")

llm = ChatOpenAI(temperature=0.6, model="deepseek-r1:70b")

pars = StrOutputParser()

chat_one = prompt_one | llm | pars
chat_two = prompt_two | llm | pars

final_chat = RunnableParallel(one_result=chat_one, two_result=chat_two)
result = final_chat.invoke({"function": "蜡烛燃烧", "topic": "婚姻法"})
print(result)
